import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;


public class ShapeManager extends JPanel {
    public static List<IShape> shapes = new ArrayList<>();

    public void addShape(IShape shape) {
        shapes.add(shape);
        repaint(); // 触发重绘
    }

    public void delShape(IShape shape) {
        shapes.remove(shape);
        repaint();
    }

    public void drawShapes() {
        repaint();
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        for (IShape shape : shapes) {
            shape.draw(g);
        }
    }
}